//
//  CustomScreenMenu.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/31.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//


#import "CustomScreenMenus.h" 
#import "CustomScreenMenuModel.h"
#import "CustomCollectionViewCell.h"
#import "CustomSendTimeCollectionCell.h"
#import "CustomCollectionSection.h"
#import "CustomCollectionFooter.h"
#import "STPickerDate.h"


#define mAnimationTime 0.5f
#define mCellHeight 48.f
#define mGap 15.f
#define itemW (KScreenWidth - 5*mGap)/4.0
@interface CustomScreenMenus ()<UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, STPickerDateDelegate>


@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, assign) CGFloat offsetY; //偏移量

@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, strong) NSIndexPath *currentIndexPath;

@property (nonatomic, strong) UILabel *aimsLab; //目标Lab
@property (nonatomic, strong) UIView *bg_line; //绿色小短线条

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

@property (nonatomic, strong) UITapGestureRecognizer *tap;

@property (nonatomic, assign) BOOL selected;

@property (nonatomic, strong) NSMutableArray *dates;

@property (nonatomic, assign) NSInteger index;

@property (nonatomic, strong) MeatShopListParam *params;


@end


@implementation CustomScreenMenus


- (void)setupUI{

    self.backgroundColor = KWhiteColor;

    [self addSubview:self.bg_line];
    [self addDropMenuView];

}

- (void)setupLayout{

    //本身高度
    self.height = 42;
    self.currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    //展开TableView的偏移量
    float mutableNavH = !self.isHiddenNav ?TJ_NavBarHeight : 0.f;
    self.offsetY = mutableNavH + self.height + self.mj_y;

    //tableView.mj_y
    self.tableView.mj_y = _offsetY;
    self.collectionView.mj_y = _offsetY;

    //
    self.bg_line.mj_y = self.height - 1;

    //titles
    [self addTitleLabels];

    //底部线条
    self.line.hidden = NO;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, self.height - 0.5, KScreenWidth, 0.5)];
    self.line.path = path.CGPath;

}


//添加标题
- (void)addTitleLabels{

    @weakify(self);
    [self.model.datas enumerateObjectsUsingBlock:^(CustomScreenMenuItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        @strongify(self);

        //Add Label
        UILabel *label = [[UILabel alloc] init];
        label.textAlignment = NSTextAlignmentCenter;
        label.frame = CGRectMake(obj.textOffsetX , 0, obj.textW, self.height);

        if (idx == 0) {
            label.attributedText = obj.selectedText;
            self.aimsLab = label;
            self.currentIndex = idx;
            self.bg_line.centerX = label.centerX;
        }else{
            label.attributedText = obj.text;
        }
        label.tag = idx + 100;
        [self addSubview:label];


        __block BOOL isDoubleChicked = YES;
        //Add Tap
        @weakify(label);
        label.tapBlock = ^{
            @strongify(label);

            if (self.currentIndex == idx) {

                if (isDoubleChicked) {
                    isDoubleChicked = NO;
                    CustomScreenMenuItem *newItem = self.model.datas[idx];
                    label.attributedText = newItem.doubleSelectionText;

                }else{

                    isDoubleChicked = YES;
                    CustomScreenMenuItem *newItem = self.model.datas[idx];
                    label.attributedText = newItem.selectedText;
                }

            }else{

                CustomScreenMenuItem *oldItem = self.model.datas[self.currentIndex];
                self.aimsLab.attributedText = oldItem.text;

                CustomScreenMenuItem *newItem = self.model.datas[idx];
                label.attributedText = newItem.selectedText;

                self.aimsLab = label;
                self.currentIndex = idx;

                [UIView animateWithDuration:mAnimationTime animations:^{
                    self.bg_line.centerX = label.centerX;
                }];


                self.bg_line.hidden = (idx != self.model.titles.count - 1) ?NO: YES;

                if (obj.type == CustomScreenMenuType_ShopOwns) {
                    [self showViewByType:CustomScreenMenuType_ShopOwns];
                    
                }else if (obj.type == CustomScreenMenuType_Screening)
                {
                    [self showViewByType:CustomScreenMenuType_Screening];
                }
                else{
                    [self dissView];
                }
            }
        };
    }];
}


/**
 添加展示层
 */
- (void)addDropMenuView{

    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:self.contentView];
    [window addSubview:self.collectionView];
    [window addSubview:self.tableView];
    self.tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dissView)];

}


#pragma mark - lifecycle methods
#pragma mark - networking methods
#pragma mark - response methods
#pragma mark - public methods

- (void)showViewByType:(CustomScreenMenuType)type{

    [self.tableView reloadData];
    [self.collectionView reloadData];
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addGestureRecognizer:self.tap];


    NSInteger rows = (self.currentIndex == 2) ?self.model.shopOwns.count : 10;
    @weakify(self);
    [UIView animateWithDuration:mAnimationTime animations:^{
        @strongify(self);

        if (type == CustomScreenMenuType_ShopOwns) {
            self.tableView.hidden = NO;
            self.tableView.frame = CGRectMake(0, self.offsetY, KScreenWidth, rows *mCellHeight);
            if (self.collectionView.height >0) {
                self.collectionView.hidden = YES;
                self.collectionView.frame = CGRectMake(0, TJ_NavBarHeight + self.height, KScreenWidth, 0);
            }

        }else if (CustomScreenMenuType_Screening){
            self.collectionView.hidden = NO;
            self.collectionView.frame = CGRectMake(0, self.offsetY, KScreenWidth, KScreenHeight - (self.offsetY +TJ_TabBarHeight+50));
            if (self.tableView.height >0) {
                self.tableView.hidden = YES;
                self.tableView.frame = CGRectMake(0, TJ_NavBarHeight + self.height, KScreenWidth, 0);
            }
        }
        self.contentView.frame = CGRectMake(0, self.offsetY, KScreenWidth, KScreenHeight - self.offsetY);


    } completion:^(BOOL finished) {

        self.contentView.alpha = 1;
    }];
}


- (void)dissView{

    self.contentView.alpha = 0;
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window removeGestureRecognizer:self.tap];


    @weakify(self);
    [UIView animateWithDuration:mAnimationTime animations:^{
        @strongify(self);
        
        if (self.tableView.height >0) {
            self.tableView.frame = CGRectMake(0, TJ_NavBarHeight + self.height, KScreenWidth, 0);
        }
        
        if (self.collectionView.height >0) {
            self.collectionView.frame = CGRectMake(0, TJ_NavBarHeight + self.height, KScreenWidth, 0);
        }
        
        self.contentView.frame = CGRectMake(0, self.offsetY, KScreenWidth, 0);
    }];
    
}


- (void)removeScreenView{
    
    if (self.tableView) {
        self.tableView.hidden = YES;
        [self.tableView removeFromSuperview];
    }
    
    if (self.collectionView) {
        self.collectionView.hidden = YES;
        [self.collectionView removeFromSuperview];
    }
    
    if (self.contentView) {
        self.contentView.hidden = YES;
        [self.contentView removeFromSuperview];
    }
}


#pragma mark - collectionview.delegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.model.screens.count;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    ScreenItem *item = self.model.screens[section];
    return item.subTitles.count;
}


- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    if(section == self.model.screens.count -1)
    {
        CGSize size = {KScreenWidth, 78};
        return size;
    }else{
        
        CGSize size = {KScreenWidth, 0};
        return size;
    }
}


- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath{
    
    if (indexPath.section == 1) {
        CGSize size = {KScreenWidth - 30, 45};
        return size;
    }else{
        CGSize size = {itemW, 45};
        return size;
    }
}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    if (kind == UICollectionElementKindSectionHeader) {
        
        CustomCollectionSection *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
        
        ScreenItem *item = self.model.screens[indexPath.section];
        header.label.text = [NSString stringWithFormat:@"%@", item.title];
        
        return header;
        
    }else{
    
        CustomCollectionFooter *footer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
        
#pragma mark - 确定
        @weakify(self);
        footer.dealOkBlock = ^{
            @strongify(self);
//            [self hiddenView];
//            if (self.resetDataBlock) {
//                self.resetDataBlock(self.params);
//            }
        };
        
#pragma mark - 重置
        footer.dealReSetBlock = ^{
            @strongify(self);
            [self.model.screens enumerateObjectsUsingBlock:^(ScreenItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
                
                NSMutableArray *aims = [NSMutableArray arrayWithArray:item.tags];
                
                [item.tags enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if (idx == 0) {
                        [aims replaceObjectAtIndex:idx withObject:@1];
                        
                    }else{
                        [aims replaceObjectAtIndex:idx withObject:@0];
                    }
                }];
                
                item.tags = [aims copy];
            }];
            
            self.dates = [NSMutableArray arrayWithArray:@[@"起始时间",@"结束时间"]];
            {
                self.params.page = @1;
                self.params.limit = @10;
                self.params.tribeId = @2;
                self.params.sex = nil;
                self.params.startTime = nil;
                self.params.endTime = nil;
                self.params.pigPositionIds = nil;
                self.params.varietiesId = nil;
                self.params.isFriend = nil;
                
            }
            
            [UIView performWithoutAnimation:^{
                [self.collectionView reloadData];
            }];
        };
        
        return footer;

    }
    return nil;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 1) {
        
        CustomSendTimeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomSendTimeCollectionCell" forIndexPath:indexPath];
        
        cell.dates = self.dates;
        
        //起始时间
        cell.dealStartBlock = ^{
            self.index = 0;
            [self showDatePicker];
        };
        
        //结束时间
        cell.dealEndBlock = ^{
            self.index = 1;
            [self showDatePicker];
        };
        
        return cell;
    }
    
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCollectionViewCell" forIndexPath:indexPath];
    
    ScreenItem *item = self.model.screens[indexPath.section];
    cell.label.text = [NSString stringWithFormat:@"%@", item.subTitles[indexPath.item]];
    cell.isChoosed = [item.tags[indexPath.item] isEqual:@1] ?YES :NO;

    return cell;
}

- (void)showDatePicker {
    STPickerDate *pickerDate = [[STPickerDate alloc]init];
    [pickerDate setYearLeast:[NSDate obtainCurrentYear] - 70];
    [pickerDate setYearSum:71];
    [pickerDate setDelegate:self];
    [pickerDate setHeightPickerComponent:40];
    pickerDate.borderButtonColor = [UIColor primaryColor];
    [pickerDate.buttonRight setTitleColor:[UIColor primaryColor] forState:UIControlStateNormal];
    [pickerDate.buttonLeft setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
    pickerDate.buttonLeft.layer.borderColor = [UIColor clearColor].CGColor;
    pickerDate.buttonRight.layer.borderColor = [UIColor clearColor].CGColor;
    [pickerDate show];
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ScreenItem *item = self.model.screens[indexPath.section];
    
    NSMutableArray *aims = [NSMutableArray arrayWithArray:item.tags];
    [item.tags enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (idx == indexPath.item) {
            [aims replaceObjectAtIndex:idx withObject:@1];
        }else if (idx != indexPath.item && [obj isEqual:@1]){
            [aims replaceObjectAtIndex:idx withObject:@0];
        }
    }];
    
    item.tags = [aims copy];
    
    [UIView performWithoutAnimation:^{
        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]];
    }];

    NSLog(@"点击了 第%ld组 %ld", indexPath.section, indexPath.item);
}



#pragma mark - tableview.delegate methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:self.currentIndexPath];
    UITableViewCell *newCell = [tableView  cellForRowAtIndexPath:indexPath];
    oldCell.accessoryView.hidden = YES;
    newCell.accessoryView.hidden = NO;

    oldCell.textLabel.textColor = mMainTextColor;
    newCell.textLabel.textColor = mMainColor;

    self.currentIndexPath = indexPath;

    if (indexPath.row != 0) {

        NSMutableAttributedString *selectedAtttibutedStr = [self.model.shopOwns[indexPath.row] createAttributingByIcon:nil downIndexImage:@"switch_one_up" textColor:mMainColor font:mMediumFont(15)];
        self.aimsLab.attributedText = selectedAtttibutedStr;
        self.aimsLab.textAlignment = NSTextAlignmentCenter;
    }else{

        NSMutableAttributedString *selectedAtttibutedStr = [@"店主属性" createAttributingByIcon:nil downIndexImage:@"switch_one_up" textColor:mMainColor font:mMediumFont(15)];
        self.aimsLab.attributedText = selectedAtttibutedStr;
        self.aimsLab.textAlignment = NSTextAlignmentCenter;
    }
}

#pragma mark - date.delegate

- (void)pickerDate:(STPickerDate *)pickerDate year:(NSInteger)year month:(NSInteger)month day:(NSInteger)day{
    
    NSString *date =  [NSString stringWithFormat:@"%ld-%ld-%ld",(long)year,(long)month,(long)day];
    int compare = [NSString compareDateByDate:date];
    if (compare == -1 ) {
        [self.viewController showHudWithMsg:@"请选择正确的时间"];
        return;
    }
    
    if (self.index == 0) {
        
        if ([self.dates[1] isEqualToString:@"结束时间"]) {
            self.params.startTime = date;
        }else{
            
            int result = [NSString compareDate:date withDate:self.dates[1]];
            if (result == 1) {
                self.params.startTime = date;
            }
            else{
                [self.viewController showHudWithMsg:@"请选择正确的时间"];
                return;
            }
        }
    }else {
        
        if ([self.dates[0] isEqualToString:@"开始时间"]) {
            self.params.endTime = date;
        }else{
            
            int result = [NSString compareDate:self.dates[0] withDate:date];
            if (result == 1) {
                self.params.endTime = date;
            }
            else{
                [self.viewController showHudWithMsg:@"请选择正确的时间"];
                return;
            }
        }
    }
    
    [self.dates replaceObjectAtIndex:self.index withObject:date];
    
    [UIView performWithoutAnimation:^{
        [self.collectionView reloadData];
    }];
    
}



#pragma mark - tableview.datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.model.shopOwns.count ;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    cell.backgroundColor = KWhiteColor;

    cell.textLabel.text = self.model.shopOwns[indexPath.row];
    cell.textLabel.font = mFont(15);

    cell.accessoryView = ({
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"meat_search_choosed"]];
        CGRect frame = imgV.frame;
        frame.size = CGSizeMake(18, 18);
        imgV.frame = frame;
        [imgV setContentMode:UIViewContentModeLeft];
        imgV;
    });

    cell.accessoryView.hidden = indexPath.row == 0 ?NO :YES;
    cell.textLabel.textColor = indexPath.row == 0? mMainColor :mMainTextColor;

    return cell;
}


#pragma mark - setter methods

- (void)setPartModel:(BuyMeatPartListModel *)partModel{
    _partModel = partModel;
    self.model.screens = [self obtainScreenData];
}

- (void)setPriceModel:(MeatPriceRangeModel *)priceModel{
    _priceModel = priceModel;
    self.model.screens = [self obtainScreenData];
}

- (void)setPigListModel:(PigVarietyList *)pigListModel{
    _pigListModel = pigListModel;
    self.model.screens = [self obtainScreenData];
}


#pragma mark - getter methods

- (UIView *)contentView{

    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        _contentView.frame = CGRectMake(0, 0, KScreenWidth, 0);
        _contentView.alpha = 0;
    }
    return _contentView;
}


- (UITableView *)tableView
{
    if (!_tableView) {

        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 0) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.separatorColor = KClearColor;
        _tableView.backgroundColor = KWhiteColor;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.rowHeight = mCellHeight;
        _tableView.bounces = NO;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    }
    return _tableView;
}


- (UICollectionViewFlowLayout *)layout{
    
    if (!_layout) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        

        _layout.minimumLineSpacing = mGap;
        _layout.minimumInteritemSpacing = mGap;
        
        _layout.itemSize = CGSizeMake(itemW, 45);
        
        _layout.sectionInset = UIEdgeInsetsMake(mGap, mGap, mGap, mGap);
        _layout.headerReferenceSize = CGSizeMake(KScreenWidth, 40);
        
        _layout.sectionHeadersPinToVisibleBounds = NO;
        
    }
    return _layout;
}


- (UICollectionView *)collectionView{
    
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0) collectionViewLayout:self.layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = KWhiteColor;
        [_collectionView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"CustomCollectionViewCell"];
        [_collectionView registerClass:[CustomSendTimeCollectionCell class] forCellWithReuseIdentifier:@"CustomSendTimeCollectionCell"];
        [_collectionView registerClass:[CustomCollectionSection class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
        [_collectionView registerClass:[CustomCollectionFooter class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
        _collectionView.bounces = NO;
        
    }
    return _collectionView;
}


- (UIView *)bg_line{

    if (!_bg_line) {
        _bg_line = [UIView new];
        _bg_line.backgroundColor = mMainColor;
        _bg_line.size = CGSizeMake(26, 1);

    }
    return _bg_line;
}


- (CustomScreenMenuModel *)model{

    if(!_model){

        _model = [[CustomScreenMenuModel alloc] init];
        _model.titles = @[@"默认", @"价格", @"店主属性", @"配送日期", @""];
        _model.nomalIcons = @[@"", @"meat_search_rank_double", @"switch_gray_down", @"meat_search_rank_double", @"meat_buy_screen_gray"];
        _model.selectedIcons = @[@"", @"switch_two_down", @"switch_one_up", @"switch_two_down", @"meat_buy_screen_green"];
        _model.doubleSelectedIcons = @[@"", @"switch_two_up", @"switch_one_up", @"switch_two_up", @"meat_buy_screen_green"];

        _model.shopOwns = @[@"全部", @"好友", @"非好友"];
        
    }
    return _model;
}


- (NSMutableArray *)dates{
    
    if (!_dates) {
        _dates = [NSMutableArray arrayWithArray:@[@"起始时间",@"结束时间"]];
    }
    return _dates;
}


- (MeatShopListParam *)params{
    
    if (!_params) {
        _params = [[MeatShopListParam alloc] init];
        _params.page = @1;
        _params.limit = @10;
        _params.tribeId = @2;
    }
    return _params;
}


- (NSArray<ScreenItem *> *)obtainScreenData{

    NSMutableArray *aims = [NSMutableArray array];

    //店主性别
    ScreenItem *shopGenderItem = [[ScreenItem alloc] init];
    shopGenderItem.title = @"店主性别";
    shopGenderItem.subTitles = @[@"全部", @"男", @"女"];
    [aims addObject:shopGenderItem];
    
    //发货时间
    ScreenItem *sendTimeItem = [[ScreenItem alloc] init];
    sendTimeItem.title = @"发货时间";
    sendTimeItem.subTitles = @[@"全部"];
    [aims addObject:sendTimeItem];
    
    //猪品种
    ScreenItem *pigTypeItem = [[ScreenItem alloc] init];
    pigTypeItem.title = @"猪品种";
    NSMutableArray *pigList = [NSMutableArray array];
    [self.pigListModel.list enumerateObjectsUsingBlock:^(PigVariety * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [pigList addObject:obj.varietiesName];
    }];
    [pigList insertObject:@"全部" atIndex:0];
    pigTypeItem.subTitles = [pigList copy];
    [aims addObject:pigTypeItem];


    
    ScreenItem *priceAttributedItem = [[ScreenItem alloc] init];
    priceAttributedItem.title = @"价格区间";
    NSMutableArray *priceList = [NSMutableArray array];

    
    NSArray *starts = [self.priceModel.list copy];
    NSArray *ends = [self.priceModel.list copy];
    [starts enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (idx < starts.count -1) {
            
            MeatPriceRangeItem *start = (MeatPriceRangeItem *)obj;
            MeatPriceRangeItem *end = (MeatPriceRangeItem *)ends[idx +1];
            NSString *myPrice = [NSString stringWithFormat:@"¥%@-%@", start.sprice, end.sprice];
            [priceList addObject:myPrice];
        }
    }];
    
    [priceList insertObject:@"全部" atIndex:0];
    priceAttributedItem.subTitles = [priceList copy];
    [aims addObject:priceAttributedItem];


    //部位种类
    ScreenItem *partTypeItem = [[ScreenItem alloc] init];
    partTypeItem.title = @"部位种类";
    NSMutableArray *parts = [NSMutableArray array];
    [self.partModel.position enumerateObjectsUsingBlock:^(BuyMeatPartModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [parts addObject:obj.positionName];
    }];

    [parts insertObject:@"全部" atIndex:0];
    partTypeItem.subTitles = [parts copy];
    [aims addObject:partTypeItem];

    return [aims copy];
}


@end


